import 'package:flutter/material.dart';
import 'package:oktoast/oktoast.dart';

class ImageView extends StatelessWidget {
  Widget _titleSection = new TitleSection();
  Widget _buttonSection = new ButtonSection();
  Widget _textSection = new Container(
    padding: const EdgeInsets.all(32.0),
    child: new Text(
      '''Lake Oeschinen lies at the foot of the Blüemlisalp in the Bernese Alps. 
      Situated 1,578 meters above sea level, it is one of the larger Alpine Lakes. 
      A gondola ride from Kandersteg, followed by a half-hour walk through pastures and pine forest, 
      leads you to the lake, which warms to 20 degrees Celsius in the summer. 
      Activities enjoyed here include rowing, and riding the summer toboggan run.''',
      softWrap: true,
    ),
  );

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
      appBar: new AppBar(
        title: new Text('这是一个布局'),
      ),
      body: new ListView(
        children: [
          new Image.asset(
            'images/cj1.jpg',
            fit: BoxFit.cover,
          ),
          _titleSection,
          _buttonSection,
          _textSection,
        ],
      ),
    );
  }
}

class ButtonSection extends StatelessWidget {
  GestureDetector _buildButtonColumn(IconData icon, String label) {
    return new GestureDetector(
      child: new Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          new Icon(icon, color: Colors.red),
          new Container(
            margin: const EdgeInsets.only(top: 8.0),
            child: new Text(
              label,
              style: new TextStyle(
                fontSize: 12.0,
                fontWeight: FontWeight.w400,
                color: Colors.blue,
              ),
            ),
          ),
        ],
      ),
      onTap: () => showToast('这是一个Toast ' + label),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      child: new Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: [
          _buildButtonColumn(Icons.call, 'CALL'),
          _buildButtonColumn(Icons.near_me, 'ROUTE'),
          _buildButtonColumn(Icons.share, 'SHARE'),
        ],
      ),
    );
  }
}

class TitleSection extends StatefulWidget {
  createState() => new TitleSectionState();
}

class TitleSectionState extends State<TitleSection> {
  bool _checked = false;
  int _count = 40;

  void _toggleFavorite() {
    setState(() {
      // If the lake is currently favorited, unfavorite it.
      if (_checked) {
        _count -= 1;
        _checked = false;
        // Otherwise, favorite it.
      } else {
        _count += 1;
        _checked = true;
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return new Container(
      padding: const EdgeInsets.all(32.0),
      child: new Row(
        children: [
          new Expanded(
            child: new Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                new Container(
                  padding: const EdgeInsets.only(bottom: 8.0),
                  child: new Text(
                    'Oeschinen Lake Campground',
                    style: new TextStyle(
                      fontWeight: FontWeight.bold,
                    ),
                  ),
                ),
                new Text(
                  'Kandersteg, Switzerland',
                  style: new TextStyle(
                    color: Colors.grey[500],
                  ),
                ),
              ],
            ),
          ),
          new Container(
            child: new IconButton(
              icon: (_checked
                  ? new Icon(Icons.star)
                  : new Icon(Icons.star_border)),
              color: Colors.red[500],
              onPressed: _toggleFavorite,
            ),
          ),
          new Text('$_count'),
        ],
      ),
    );
  }
}
